#pragma once

#include <iostream>
#include <string>
#include <fstream>
#include <boost/algorithm/string.hpp>

#include "Log.hpp"
#include "cppjieba/Jieba.hpp"



namespace UtilArea
{
    using namespace LogArea;
    class FileUtil
    {
    public:
        static bool ReadUtil(const std::string& file,std::string& result)
        {
            std::ifstream in(file,std::ios::in);    // 读取
            if(!in.is_open())
            {
                LogArea::LOG(LogLevel::ERROR)<<"open file:" << file <<" error";
                return false;
            }


            std::string line;
            while(std::getline(in,line))    // 逐行读取 file 文件中的内容放入result中
            {
                result+=line;
            }

            return true;
        }
    };


    class StringUtil
    {
    public:
        // 分隔字符串,分隔的结果一个个存入 result 中
        static void Split(const std::string& line,std::vector<std::string>& result,const std::string& sep)
        {
            // aaaaa\3bbbbbb\3ccccc\3 --> aaaaa bbbbbb ccccc
            // aaaaa\3\3\3\3bbbbbb\3ccccc\3  --> aaaaa bbbbbb ccccc
            boost::split(result,line,boost::is_any_of(sep),boost::token_compress_on);
        }
    };


    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";

    // 分词
    class JiebaUtil
    {
    public:
        static void CutString(const std::string& src,std::vector<std::string>& out)
        {
            jieba.CutForSearch(src,out);
        }
    private:
        static cppjieba::Jieba jieba;
    };

    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH); 
}